<template>
  <a-row gutter="16">
    <a-col :span="8">
      <a-descriptions size="small" :column="1" bordered>
        <a-descriptions-item label="采集模式">
          <a-select v-model:value="registerConfig.mode" :options="modeList" style="width: 100%;"></a-select>
        </a-descriptions-item>
        <a-descriptions-item label="串口名称" v-if="registerConfig.mode=='serial'">
          <a-input v-model:value="registerConfig.name"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="波特率" v-if="registerConfig.mode=='serial'">
          <a-input v-model:value="registerConfig.baudRate"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="从站IP" v-if="registerConfig.mode=='network'">
          <a-input v-model:value="registerConfig.host"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="从站端口" v-if="registerConfig.mode=='network'">
          <a-input v-model:value="registerConfig.port"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="采集从站地址">
          <a-input v-model:value="registerConfig.serverAddress"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="自动采集间隔">
          <a-flex>
            <a-input v-model:value="registerConfig.sendInterval" addon-after="秒"></a-input>
          </a-flex>

        </a-descriptions-item>
        <a-descriptions-item label="输入寄存器[04]-自动采集起始地址">
          <a-input v-model:value="registerConfig.readStartAddress"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="输入寄存器[04]-连续采集数量">
          <a-input v-model:value="registerConfig.quantity"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="保持寄存器[03]-自动采集起始地址">
          <a-input v-model:value="registerConfig.keepReadStartAddress"></a-input>
        </a-descriptions-item>
        <a-descriptions-item label="保持寄存器[03]-连续采集数量">
          <a-input v-model:value="registerConfig.keepQuantity"></a-input>
        </a-descriptions-item>
      </a-descriptions>

      <a-card size="small" :bordered="false">
        <a-flex justify="end">
          <a-button type="primary" ghost @click="save"> 保存</a-button>
        </a-flex>
      </a-card>
    </a-col>
  </a-row>
</template>
<script setup>

import {ref} from "vue";
import {baseRequest} from "@/utils/request.js";
import {message} from "ant-design-vue";
const modeList = ref([
  {
    label:"Modbus RTU",
    value:"serial",
  },
  {
    label:"Modbus TCP",
    value:"network",
  }
])
const registerConfig = ref({})

baseRequest("/config/get/control", {}).then(res => {
  registerConfig.value = res.data.data
  delete registerConfig.value.port104
  delete registerConfig.value.forwardMode104
  delete registerConfig.value.threeAdd104
  delete registerConfig.value.threeSwitchAdd104
})
const save = () => {
  baseRequest("/config/set/control", registerConfig.value, 'post').then(res => {
    if (res.data.code == 200) {
      message.success("保存成功，重启服务后生效")
    } else {
      message.error(res.data.message)
    }
  })
}
</script>

<style scoped>

</style>
